define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'reportschool/index' + location.search,
                    add_url: 'reportschool/add',
                    edit_url: 'reportschool/edit',
                    del_url: 'reportschool/del',
                    multi_url: 'reportschool/multi',
                    import_url: 'reportschool/import',
                    month_url: 'reportschool/month',
                    year_url: 'reportschool/year',
                    table: 'report_school',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {field: 'school_name', title: __('学校名称'),operate:false},
                        {field: 'school_id', title: __('学校名称'),searchList: Config.schoolConfig,visible:false},
                        {field: 'grade_nums', title: __('Grade_nums'),operate:false},
                        {field: 'class_nums', title: __('Class_nums'),operate:false},
                        {field: 'user_nums', title: __('User_nums'),operate:false},
                        {field: 'vip_nums', title: __('Vip_nums'),operate:false},
                        {field: 'vip_amt', title: __('Vip_amt'),operate:false},
                        {field: 'vip_3_nums', title: __('Vip_3_nums'),operate:false},
                        {field: 'vip_1_nums', title: __('Vip_1_nums'),operate:false},
                        {field: 'vip_2_nums', title: __('Vip_2_nums'),operate:false},
                        {field: 'vip_1_amt', title: __('Vip_1_amt'),operate:false},
                        {field: 'vip_2_amt', title: __('Vip_2_amt'),operate:false},
                        {field: 'vip_3_amt', title: __('Vip_3_amt'),operate:false},
                        {field: 'date', title: __('Date'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'create_time', title: __('Create_time'), operate:false, addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {
                            field: 'buttons',
                            width: "120px",
                            title: __('操作'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.buttons,
                            buttons: [
                                {
                                    name: 'detail',
                                    text: __('月统计'),
                                    title: __('月统计'),
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    icon: 'fa fa-list',
                                    url: 'reportschool/month',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        return true;
                                    }
                                },
                                {
                                    name: 'detail',
                                    text: __('年统计'),
                                    title: __('年统计'),
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    icon: 'fa fa-list',
                                    url: 'reportschool/year',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        return true;
                                    }
                                },
                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        month: function () {
            Table.api.init({
                extend: {
                    month_url: 'reportschool/month/ids/'+Config.id,
                    table: 'report_school',
                }
            });


            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.month_url,
                pk: 'id',
                sortName: 'id',
                showToggle: false,
                showColumns: false,
                commonSearch: false,
                search:false,
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {field: 'school_name', title: __('学校名称'),operate:false},
                        {field: 'grade_nums', title: __('Grade_nums'),operate:false},
                        {field: 'class_nums', title: __('Class_nums'),operate:false},
                        {field: 'user_nums', title: __('User_nums'),operate:false},
                        {field: 'vip_nums', title: __('Vip_nums'),operate:false},
                        {field: 'vip_amt', title: __('Vip_amt'),operate:false},
                        {field: 'vip_3_nums', title: __('Vip_3_nums'),operate:false},
                        {field: 'vip_1_nums', title: __('Vip_1_nums'),operate:false},
                        {field: 'vip_2_nums', title: __('Vip_2_nums'),operate:false},
                        {field: 'vip_1_amt', title: __('Vip_1_amt'),operate:false},
                        {field: 'vip_2_amt', title: __('Vip_2_amt'),operate:false},
                        {field: 'vip_3_amt', title: __('Vip_3_amt'),operate:false},
                        {field: 'month', title: __('月份'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
             },
        year: function () {
            Table.api.init({
                extend: {
                    year_url: 'reportschool/year/ids/'+Config.id,
                    table: 'report_school',
                }
            });


            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.year_url,
                pk: 'id',
                sortName: 'id',
                showToggle: false,
                showColumns: false,
                commonSearch: false,
                search:false,
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {field: 'school_name', title: __('学校名称'),operate:false},
                        {field: 'grade_nums', title: __('Grade_nums'),operate:false},
                        {field: 'class_nums', title: __('Class_nums'),operate:false},
                        {field: 'user_nums', title: __('User_nums'),operate:false},
                        {field: 'vip_nums', title: __('Vip_nums'),operate:false},
                        {field: 'vip_amt', title: __('Vip_amt'),operate:false},
                        {field: 'vip_3_nums', title: __('Vip_3_nums'),operate:false},
                        {field: 'vip_1_nums', title: __('Vip_1_nums'),operate:false},
                        {field: 'vip_2_nums', title: __('Vip_2_nums'),operate:false},
                        {field: 'vip_1_amt', title: __('Vip_1_amt'),operate:false},
                        {field: 'vip_2_amt', title: __('Vip_2_amt'),operate:false},
                        {field: 'vip_3_amt', title: __('Vip_3_amt'),operate:false},
                        {field: 'year', title: __('年份'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
             },

        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
